package rab.security.trap;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

// Test code removed from receiver
/*			String state = extras.getString(TelephonyManager.EXTRA_STATE);
Log.w("DEBUG", "State = " + state);

if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
	String phoneNumber = extras
			.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
	Log.e("DEBUG", "Phone Number = " + phoneNumber);
}
*/			
//Log.w("DEBUG", "We are an Ordered Broadcast"+ isOrderedBroadcast());
/*			if (isOrderedBroadcast()) {
	Log.w("DEBUG", "We are an Ordered Broadcast");
	//abortBroadcast();
}
if (! isOrderedBroadcast()) {
	Log.w("DEBUG", "What the hell, unordered is no good!");
}
*/

/* Broadcast Receiver for the New Outgoing Call intent */
public class MyPhoneReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		Log.w("DEBUG", "Receiver called MyPhoneReceiver"); //show I got here
		Bundle extras = intent.getExtras(); //I'll need the extras for the message, specifically the phone number
		if (extras != null) {
			if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) { //This must be the new outgoing call

				// get phone number from bundle
	            String phoneNumber = extras.getString(Intent.EXTRA_PHONE_NUMBER);

	            Toast.makeText(context, "Call:  "+phoneNumber+" - changing number to 411.", Toast.LENGTH_LONG).show();
	            setResultData("411"); //This is the correct method of resetting a value down the chain. (hard to 411 for now, NULL if we want it to be no dial)
			}
			
		}
	}
}